package com.o2o.cleaning.month.platform.ebusiness_plat.taobao

import com.o2o.utils.Iargs
import org.apache.spark.sql.SparkSession

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2021/2/2 15:54
  * @ Param:  ${PARAM}
  * @ Description: 
  */
object SwbPlatYoy {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder()
      .appName(s"${this.getClass.getSimpleName}")
      .config("spark.debug.maxToStringFields", "2000")
      .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
      .getOrCreate()

    val sc = spark.sparkContext
    sc.hadoopConfiguration.set("fs.s3a.access.key", Iargs.OBSACCESS)
    sc.hadoopConfiguration.set("fs.s3a.secret.key", Iargs.OBSSECRET)
    //    sc.hadoopConfiguration.set("fs.s3a.endpoint", Iargs.OBSENDPOINT)
    sc.setLogLevel("WARN")

    //天猫

    spark.read.orc("s3a://dws-data/g_data/2020/9/tmall/").registerTempTable("t1")
    spark.read.orc("s3a://dws-data/g_data/2020/10/tmall/").registerTempTable("t2")
    spark.read.orc("s3a://dws-data/g_data/2020/11/tmall/").registerTempTable("t3")
    spark.read.orc("s3a://dws-data/g_data/2020/12/tmall/").registerTempTable("t4")

    val df9_10 = spark.sql(
      """
        |select
        |goodct,
        |shopct
        |from
        |(select
        |count(1) goodct
        |from
        |(
        |select
        |good_id
        |from
        |(select
        |good_id
        |from
        |t1
        |)
        |union all
        |(
        |select
        |good_id
        |from
        |t2
        |)
        |group by good_id
        |)
        |) t1
        |left join
        |(select
        |count(1) shopct
        |from
        |(
        |select
        |good_id
        |from
        |(select
        |good_id
        |from
        |t1
        |)
        |union all
        |(
        |select
        |good_id
        |from
        |t2
        |)
        |group by good_id
        |)
        |) t2
        |on 1=1
      """.stripMargin).cache()

    val d11_12 = spark.sql(
      """
        |select
        |goodct,
        |shopct
        |from
        |(select
        |count(1) goodct
        |from
        |(
        |select
        |good_id
        |from
        |(select
        |good_id
        |from
        |t3
        |)
        |union all
        |(
        |select
        |good_id
        |from
        |t4
        |)
        |group by good_id
        |)
        |) t1
        |left join
        |(select
        |count(1) shopct
        |from
        |(
        |select
        |good_id
        |from
        |(select
        |good_id
        |from
        |t3
        |)
        |union all
        |(
        |select
        |good_id
        |from
        |t4
        |)
        |group by good_id
        |)
        |) t2
        |on 1=1
      """.stripMargin).cache()





  }

}
